<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no" />
    <title>图片转PDF</title>
    <!--标准mui.css-->
    <link rel="stylesheet" href="../css/mui.min.css" />
    <script src="../js/mui.min.js"></script>
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="../css/app.css" />
    <link rel="stylesheet" href="../npl/css/vant.mini.css" />
    <script src="../js/vue.js"></script>
    <script src="../js/jquery-3.6.0.min.js"></script>
    <script src="../js/sm2.js"></script>
    <script src="../js/sm3.js"></script>
    <script src="../js/vconsole.min.js"></script>
    <script src="../js/feedback.js"></script>
    <script src="../js/clipboard.js"></script>
    <script src="../js/flexible.js"></script>
    <script src="../wx/uap.js"></script>
    <script src="../npl/js/vant.mini.js"></script>
    <script src="./text.js" type="text/javascript"></script>
</head>
<style>
    html,
    body,
    #app {
        overflow: hidden;
    }

    /* WebKit browsers */

    ::-webkit-input-placeholder {
        color: #d8e6fe;
    }

    /* Mozilla Firefox 4 to 18 */

    :-moz-placeholder {
        color: #d8e6fe;
        opacity: 1;
    }

    /* Mozilla Firefox 19+ */

    ::-moz-placeholder {
        color: #d8e6fe;
        opacity: 1;
    }

    /* Internet Explorer 10+ */

    :-ms-input-placeholder {
        color: #d8e6fe;
    }

    .mui-toast-container {
        top: 50%;
    }

    .header_text {
        min-height: 0.5rem;
        position: relative;
        /* margin-top: -42.5px; */
        background: url("../image/back-2.png") no-repeat center;
        background-size: 100% 100%;
    }

    .header_upload {
        /* height: 2.8rem; */
        /* max-height: 9rem; */
        position: relative;
        margin-top: 8px;
        overflow: hidden;
        box-sizing: border-box;
    }

    .header_voice {
        height: 2.5rem;
        position: relative;
        margin-top: 8px;
        background: url("../image/back-2.png") no-repeat center;
        background-size: 100% 100%;
    }

    .header_sit {
        height: 2rem;
        position: relative;
        margin-top: 8px;
        background: url("../image/back-2.png") no-repeat center;
        background-size: 100% 100%;
    }

    .left {
        text-align: center;
    }

    .left a {
        line-height: 0.5rem;
        color: rgb(30, 55, 84);
    }

    .left .left1 {
        position: absolute;
        left: 0.1rem;
        top: 0.25rem;
    }

    .left :nth-child(1) span {
        line-height: 0.5rem;
        color: #fff;
    }

    .left :nth-child(2) span {
        line-height: 0.5rem;
        color: #fff;
    }

    .wrapper {
        padding: 0 10px 10px;
        /* height: calc(100% - 100px); */
        overflow: scroll;
        position: relative;
        box-sizing: border-box;
    }

    .text_title {
        height: 30px;
        padding: 2% 5% 0;
        position: relative;
        /* border-bottom: 1px solid #8a9dbe; */
        /* background:turquoise; */
        /* line-height: 30px;         */
    }

    .first_span {
        width: 3px;
        border-radius: 20% 20%;
        display: inline-block;
        height: 15px;
        background: #19aeb0;
    }

    .first_span_text {
        font-weight: 600;
        font-size: 15px;
        color: #1e3754;
        position: absolute;
        left: 8%;
        top: 30%;
    }

    .first_span_img {
        /* position: absolute;
     left: 25%;
     top: 36%; */
        margin-left: 5px;
        color: red;
    }

    .upload_wrapper {
        width: 96%;
        max-height: 9rem;
        margin: auto;
        margin-top: 8px;
        padding-left: 8px;
        overflow-y: scroll;
        padding: 5px 0px 0;
        box-sizing: border-box;
        padding-bottom: 12px;
    }

    .List_wrapper {
        width: 95%;
        /* height: calc(3.5rem - 55px); */
        margin: auto;
        display: flex;
        flex-wrap: wrap;
        padding: 0px 5px 12px;
        justify-content: space-around;
    }

    .List {
        width: 45%;
        height: 34px;
        border: 2px solid #d3e3fe;
        font-weight: 500;
        color: #8a9dbe;
        border-radius: 4px;
        padding-left: 1%;
        padding-top: 1.2%;
        margin-top: 4px;
    }

    .List_img {
        width: 14px;
        height: 14px;
        display: inline-block;
        margin-bottom: 5px;
    }

    .duihao {
        vertical-align: middle;
        width: 100%;
        height: 100%;
    }

    /* 点击之后的样式 */

    .btn_selected {
        border: 2px solid rgba(95, 132, 247, 1);
        border-radius: 4px;
        font-weight: 500;
        color: #1e3754;
    }

    .upload_img {
        width: 28.7%;
        height: 90px;
        border-radius: 8px;
        border: 1px dashed #bcbebe;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        padding: 2px;
        position: relative;
        margin: 8px 2%;
        float: left;
        box-sizing: border-box;
    }

    /* .upload_img:nth-child(2n) {
        margin-right: 5%;
        margin-left: 5%;
    } */

    .img_active {
        width: 28%;
        height: 80px;
        /* padding: 20px; */
        background: #ffffff;
        border-radius: 8px;
        opacity: 0;
    }

    .quxiao {
        position: absolute;
        right: -10%;
        top: -8%;
        display: block;
        width: 22%;
        height: 25%;
    }

    .chenggong {
        position: absolute;
        left: 38%;
        bottom: -6%;
        display: block;
        width: 28%;
        height: 20%;
    }

    .upimg {
        margin-top: 10px;
        width: 36px;
        height: 30px;
        background: url("../image/camera.png") no-repeat;
        background-size: 100% 100%;
    }

    .up_text {
        font-weight: 500;
        font-size: 12px;
        color: #8a9dbe;
    }

    .foot {
        position: fixed;
        bottom: 0px;
        left: 0px;
        padding: 0.2rem;
        width: 100%;
        text-align: center;
        display: flex;
        justify-content: space-around;
    }

    .inp {
        display: inline-block;
    }

    input[type="text"] {
        width: 250px;
        height: 50px;
        margin-bottom: 0;
    }

    .derive {
        width: 100px;
        height: 50px;
         background-color: #5f84f7;
            border-radius: 12px;
            color: #fff;
            font-weight: 600;
    }

    .foots {
        position: fixed;
        bottom: 0px;
        left: 0px;
        padding: 0.2rem;
        background-color: #ffffff;
        border-radius: 20px 20px 0 0;
        width: 100%;
        font-size: 14px;
        z-index: 99999;
        color: #8a9dbe;
    }

    .foots p {
        color: #1e3754;
        font-size: 16px;
        font-weight: 600;
        margin: 20px 0;
    }

    .foots input {
        margin: 0 0 20px 0;
        color: #223533;
    }

    .foots div {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    .del_btn1 {
        width: 45%;
        height: 40px;
        /* box-shadow: 0px 16px 16px 0px rgba(4, 124, 137, 0.05); */
        /* border-radius: 8px; */
        background-color: rgba(45, 52, 60, 0.07);
        border-radius: 48px;
        color: rgba(45, 52, 60, 0.8);
        font-size: 16px;
        font-family: PingFang SC;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
    }

    .del_btn2 {
        width: 45%;
        height: 40px;
        background-color: #19aeb0;
        border-radius: 48px;
        color: #fff;
        font-weight: 600;
    }

    .home {
        border: none;
    }

    .my {
        border: none;
    }

    .text_wrapper {
        width: 90%;
        margin: auto;
        margin-top: 10px;
        height: calc(2.5rem - 55px);
        display: flex;
        justify-content: space-between;
        padding: 10px 4px 0 0;
        border-top: 1px dashed #cacfcf;
    }

    .text_wrapper_site {
        width: 90%;
        margin: auto;
        margin-top: 5px;
        height: calc(2.5rem - 55px);
        display: flex;
        justify-content: space-between;
        padding: 0 4px 0 0;
    }

    #input {
        width: 80%;
        height: 90%;
    }

    .voice_btn {
        /* display: inline; */
        width: 60px;
        height: 50px;
        text-align: center;
        line-height: 67px;
        background: #f7faff;
        border-radius: 8px;
        margin-left: 5px;
        /* margin-top: 2%; */
    }

    .site_btn {
        width: 50px;
        height: 50px;
        text-align: center;
        line-height: 60px;
        background: #f7faff;
        border-radius: 8px;
        margin-left: 5px;
    }

    .site_img {
        display: inline;
        width: 40%;
        height: 46%;
    }

    .voice_img {
        display: inline;
        width: 35%;
        height: 55%;
    }

    .clipboardContent {
        font-size: 12px;
        margin-bottom: 0;
        padding: 5px;
    }

    .clipboardContent_site {
        font-size: 12px;
        height: 40px;
        margin-bottom: 0;
        line-height: 16px;
        margin-top: 4px;
        border: none;
        height: 46px;
        padding: 22px 0 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    }

    .texts {
        width: 95%;
        margin: auto;
        /* margin: 0.1rem 0rem 0; */
        color: rgb(185, 196, 216);
        background-color: #fff;
        font-weight: 600;
    }
    .numImg {
        padding: 2% 5% 0;
        color: rgba(45, 52, 60, 0.6);
        font-size: 12px;
    }
</style>

<body> 
    <div id="app" style="background-image: url('../image/back_home.png');"  v-cloak>
        <div class="is-loading">
            <div class="curtain">
                <div class="loadingBgc">
                    <div class="loader"></div>
                </div>
            </div>         
        </div>
        <div class="trainTicketstitle">
            <div class="header_tit">
                <van-nav-bar title="图片转PDF" left-arrow>
                    <template #left>
                        <div class="back_l" @click="home"><img src="../image/left.png" alt=""></div>
                    </template>
                    <!-- <template #right>
                        <div class="back_r" @click="close"><img src="../image/del.png" alt=""></div>
                    </template> -->
                </van-nav-bar>
            </div>
            </div>
        <div class="wrapper">
            <div class="header_upload">
                <div class="text_title">
                    <span class="first_span" style="margin-top: 5px"></span>
                    <span class="first_span_text">
                        <span>上传图片</span>
                        <span class="first_span_img">*</span>
                    </span>
                </div>
                <div class="numImg">单次最多上传三张图片，共计可传20张，PDF直接发到邮箱</div>
                <div class="upload_wrapper">
                    <div class="upload_img" v-for="(item, index) in addedPreviewFile" :style="item.style">
                        <img v-if="addedPreviewFile" :src="item.localDatas" style="width: 100%; height: 100%" alt=""
                            ref="img" v-if="addedPreviewFile" />
                        <img @click="delImg(index)" v-if="addedPreviewFile" class="quxiao"
                            src="../image/quxiao1.png" alt="" />
                    </div>
                    <div class="upload_img" @click="functionBtn" v-if="addedPreviewFile.length < 20">
                        <div class="upimg"></div>
                        <div class="up_text">点击上传</div>
                        <!-- @change="funcBtn" -->
                        <input type="file" id="inputer" class="file-input4 file-input"
                            style="display: none; width: 100%; height: 100%" ref="inputer" />
                    </div>
                    <!-- <div class="img_active"  v-if="addedPreviewFile.length % 3 != 0"></div> -->
                </div>
            </div>
        </div>
        
        <div class="foot">
            <button class="del_btn1" @click="home">取消</button>
            <button  class="del_btn2" @click="sendEmail">发送邮箱</button>
        </div>
        <!-- <div v-if="isShow" class="foot">
            <input class="inp" type="text" v-model="name" :readonly="read ? false : 'readonly'" @click="funcBt" />
            <button class="derive" @click="Derive">发送邮箱</button>
        </div>
        <div v-if="show" class="foots">
            <p>修改文件名称</p>
            文件名称：<input class="inp" type="text" v-model="name" placeholder="输入中英文、数字、下划线！"
                oninput="if(value.length>20) value=value.slice(0,20)" />
            <div>
                <button class="del_btn1" @click="quxiao">取消</button>
                <button class="del_btn2" @click="continueBtn">确定</button>
            </div>
        </div> -->
    </div>
    <script>
        new Vue({
            el: "#app",
            data() {
                $.getScript("../js/jweixin-sgccigw-1.0.0.js" /*"js/jweixin-1.0.0.js"*/, function () {
                    'use strict';
                    wx.ready(function () { });
                    jsApiList = [
                        'chooseImage',
                        'getLocalImgData',
                        'previewImage',
                        'uploadImage',
                        'downloadImage',
                        'onHistoryBack',
                        'closeWindow',
                        'launch3rdApp',

                        'ocr',
                        "getLocalResPath",
                        "ext_FileManager_Information",
                        " ext_Net_PathExtension"
                    ];
                    wx.config({
                        beta: true,
                        debug: false,
                        appId: corpid,
                        timestamp: '1626832073',
                        nonceStr: nonceStr,
                        signature: signature,
                        jsApiList: jsApiList
                    });
                });
                return {
                    slocalResPath: [],
                    showUpload: true,
                    localIds: [],
                    content: "",
                    // 上传的图片
                    addedPreview: [], // 临时存储
                    addedPreviewFile: [], // 最终存储
                    addedPreviewFileIds: [],
                    isflageIOX: true,
                    name: "AI助手生成PDF",
                    isShow: true,
                    show: false,
                    // 随机字符串
                    batchId: "",
                    // 禁止修改
                    read: 0,
                    // 图片
                    pic: {},
                };
            },
            created() {
                this.compatibleInput();
            },
            computed: {},
            methods: {
                //  判断安卓还是ios
                compatibleInput() {
                    this.isShow = true;
                    //获取浏览器的userAgent,并转化为小写
                    var ua = navigator.userAgent.toLowerCase();
                    //判断是否是苹果手机，是则是true
                    var isIos = ua.indexOf("iphone") != -1 || ua.indexOf("ipad") != -1;
                    if (isIos) {
                        this.isflageIOX = true;
                    } else {
                        this.isflageIOX = false;
                    }
                    // 随机字符串
                    var $chars = "abcdefghijklmnpqrstwxyz2345678";
                    var maxPos = $chars.length;
                    this.batchId = "";
                    for (var i = 0; i < 32; i++) {
                        this.batchId += $chars.charAt(Math.floor(Math.random() * maxPos));
                    }
                },
                // 返回
                home() {
                    if (this.addedPreviewFile.length) {
                        var btnArray = ["取消", "确定"];
                        var i = 0;
                        mui.confirm(
                            "未发送邮箱，是否退出？",
                            "消息提醒",
                            btnArray,
                            (e) => {
                                if (i > 0) return;
                                i++;
                                if (e.index == 1) {
                                    this.delfile();
                                    $(location).attr("href", "Home.html?ssflag=ssflag");
                                } else {
                                    // $(location).attr("href", "Voice.html");
                                }
                            }
                        );
                    } else {
                        $(location).attr("href", "Home.html?ssflag=ssflag");
                    }
                },
                // 删除照片
                delImg(index) {
                    $(".curtain").css("display", "block");
                    // 1: 取要删除的id
                    const delid = this.addedPreviewFileIds[index];
                    // 删除addedPreviewFile index
                    this.delfile(delid, index);
                },
                delfile(id, index) {
                    const userId = sessionStorage.getItem("userId");
                    let AuthenticationSession =
                        sessionStorage.getItem("Authentication");
                    let iscp_port;
                    if (sessionStorage.getItem("iscp_port")) {
                        iscp_port = sessionStorage.getItem("iscp_port");
                    } else {
                        iscp_port = "";
                    }
                    const timestamp = new Date().getTime() + ""; //时间戳
                    let data = {
                        ids: id,
                        timestamp: timestamp
                    };
                    data = JSON.stringify(data);
                    let sign = sm3(data);
                   setTimeout(() => {
                    $.ajax({
                        url: localUrlLink + iscp_port + "/photoTransfer/storage/deleteImage",
                        type: "post",
                        // async: false, //是否同步，false表示同步请求
                        dataType: "json",
                        data: data,
                        headers: {
                            "Content-Type": "application/json;charset=UTF-8",
                            Authentication: AuthenticationSession,
                            sign: sign,
                            timestamp: timestamp,
                            userId: userId
                        },
                        success: (res, txt, xhr) => {
                            if (res.code == 200) {
                                if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                                    let Authentication = xhr.getResponseHeader("Authentication");
                                    if (Authentication) {
                                        sessionStorage.setItem("Authentication", Authentication);
                                        // 成功
                                        $(".curtain").css("display", "none");
                                        this.addedPreviewFile.splice(index, 1);
                                        this.addedPreviewFileIds.splice(index, 1);
                                        mui.toast(res.resultValue, {
                                            duration: "long",
                                            type: "div",
                                        });
                                    }
                                } else {
                                    $(".curtain").css("display", "none");
                                    mui.toast("完整性校验失败！", {
                                        duration: "long",
                                        type: "div",
                                    });
                                }
                            } else {
                                $(".curtain").css("display", "none");
                                mui.toast(res.resultValue, {
                                    duration: "long",
                                    type: "div",
                                });
                            }
                        },
                        error: function (e) {
                            $(".curtain").css("display", "none");
                            mui.toast("请求异常，请稍后再试！", {
                                duration: "long",
                                type: "div",
                            });
                        },
                    });
                   })
                },
                // 点击上传照片逻辑
                functionBtn() {
                    // 判断IOS/安卓   上面是为了本地测试，但是部署的时候ios需要调用wx方法
                    if (this.isflageIOX == true) {
                        // 每次上传三张
                        var count = 20 - this.addedPreviewFile.length;
                        var count1 = "";
                        if (count < 3) {
                            count1 = count
                        } else {
                            count1 = 3;
                        }
                        wx.chooseImage({
                            count: count1, // 默认9
                            sizeType: ["compressed"], // 可以指定是原图还是压缩图，默认二者都有
                            sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
                            quality: 0.5, //压缩质量，范围0～1，数值越小，质量越低，压缩率越高（仅对jpg有效）
                            success: (res) => {
                                // var localIds = res.localIds[0]; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                                this.slocalResPath = [];
                                $(".curtain").css("display", "block");
                                res.localIds.forEach((item, index) => {
                                    this.loopList(item, () => {
                                        if (index === res.localIds.length - 1) {
                                            this.checkList("ios");
                                        }
                                    });
                                });
                            },
                        });
                    } else {
                        // 每次上传三张
                        var count = 20 - this.addedPreviewFile.length;
                        var count1 = "";
                        if (count < 3) {
                            count1 = count
                        } else {
                            count1 = 3;
                        }
                        wx.chooseImage({
                            count: count1, // 默认9
                            sizeType: ["compressed"], // 可以指定是原图还是压缩图，默认二者都有
                            sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
                            quality: 0.5, //压缩质量，范围0～1，数值越小，质量越低，压缩率越高（仅对jpg有效）
                            success: (res) => {
                                // var localIds = res.localIds[0]; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                                this.slocalResPath = [];
                                $(".curtain").css("display", "block");
                                res.localIds.forEach((item, index) => {
                                    this.loopList(item, () => {
                                        if (index === res.localIds.length - 1) {
                                            this.checkList("Android");
                                        }
                                    });
                                });
                            },
                        });
                    }
                },
                loopList(localIds, callBack) {
                    wx.invoke(
                        "getLocalResPath", {
                        localId: localIds,
                    },
                        (res) => {
                            this.slocalResPath.push(res.localResPath);
                            this.getImage(res.localResPath, localIds);
                            callBack();
                        }
                    );
                },

                getImage(slocalResPath, localIds) {
                    wx.invoke(
                        "ext_FileManager_Information", {
                        data: {
                            path: slocalResPath,
                        },
                    },
                        (res) => {
                            let str = JSON.parse(res.data);
                            str = str.fileSize.split(".");
                            if (str[1].indexOf("MB") !== -1) {
                                if (Number(str[0]) >= 15) {
                                    mui.toast("图片大小不能超过15MB", {
                                        duration: "long",
                                        type: "div",
                                    });
                                } else {
                                    this.getImgBase(localIds);
                                }
                            } else {
                                this.getImgBase(localIds);
                            }
                        }
                    );
                },
                getImgBase(localIds) {
                    this.addedPreview = [];
                    // 根据id取图片的路径
                    wx.getLocalImgData({
                        localId: localIds,
                        success: (res) => {
                            var localData = res.localData;
                            if (localData.indexOf("data:image") != 0) {
                                //判断是否有这样的头部
                                localData = "data:image/jpeg;base64," + localData;
                            }
                            localData = localData
                                .replace(/\r|\n/g, "")
                                .replace("data:image/jpg", "data:image/jpeg");
                            // 第一个替换的是换行符，第二个替换的是图片类型，因为在IOS机上测试时看到它的图片类型时jgp，
                            // 这不知道时什么格式的图片，为了兼容其他设备就把它转为jpeg
                            this.addedPreview.push({
                                localDatas: localData
                            }); // 返回图片的服务器端ID
                        },
                    });
                },
                // 上传图片的路径
                checkList(ios) {
                    if (sessionStorage.getItem("iscp_port")) {
                        iscp_port = sessionStorage.getItem("iscp_port");
                    } else {
                        iscp_port = "";
                    }
                    const userId = sessionStorage.getItem("userId");
                    const orgId = sessionStorage.getItem("unitId");
                    const regEx = ".+/(.+)$";
                    var datas = {
                        cellphone: ios,
                        batchId: this.batchId,
                    },
                        files = {};
                    this.slocalResPath.forEach((item, index) => {
                        var a = index + 1;
                        datas["filename" + a] = item.match(regEx)[0];
                        datas["originalname" + a] = item.match(regEx)[0];
                        files["file" + a] = item;
                    });
                    this.pic = files;
                    var channelId = "net_upload_" + this.createNonceStr(8);
                    const timestamp = new Date().getTime() + "";
                    let signTime = sm3(timestamp + "&" + userId);
                    let AuthenticationSession =
                        sessionStorage.getItem("Authentication");
                    var param = {
                        id: channelId,
                        timeout: "60",
                        url: localUrlLink + iscp_port +"/photoTransfer/IdentificationFile/pictureToPdf",
                        header: {
                            "Content-Type": "application/json;charset=UTF-8",
                            sign: signTime,
                            Authentication: AuthenticationSession,
                            timestamp: timestamp,
                            userId: userId,
                            orgId: orgId, //单位id
                        },
                        data: datas,
                        files: files,
                    };
                    wx.invoke(
                        "ext_Net_Upload", {
                        data: param,
                    },
                        (res) => {
                            console.log(res,"res_____")
                            if (res.event == "fail") {
                                $(".curtain").css("display", "none");
                                mui.toast("上传失败，请稍后再试!", {
                                    duration: "long",
                                    type: "div",
                                });
                            } else {
                                $(".curtain").css("display", "none");
                                const result = JSON.parse(res.result);
                                if (result.code == 200) {
                                    const resultValue = JSON.parse(result.resultValue);
                                    if (sm3(resultValue.id) == resultValue.sign) {
                                        let Authentication = resultValue.Authentication;
                                        if (Authentication) {
                                            sessionStorage.setItem(
                                                "Authentication",
                                                Authentication
                                            );
                                            ids = resultValue.id.split(",");
                                            if (!this.addedPreviewFileIds ||
                                                this.addedPreviewFileIds.length == 0
                                            ) {
                                                this.addedPreviewFileIds = [...ids];
                                            } else {
                                                this.addedPreviewFileIds = [
                                                    ...this.addedPreviewFileIds,
                                                    ...ids,
                                                ];
                                            }
                                            if (!this.addedPreviewFile) {
                                                this.addedPreviewFile = this.addedPreview;
                                            } else {
                                                this.addedPreview.forEach((item) => {
                                                    this.addedPreviewFile.push(item);
                                                });
                                            }
                                            mui.toast("上传成功", {
                                                duration: 1500,
                                                type: "div",
                                            });
                                            
                                        }
                                    }
                                } else {
                                    $(".curtain").css("display", "none");
                                    mui.toast(result.resultValue, {
                                        duration: "long",
                                        type: "div",
                                    });
                                }
                            }
                        }
                    );
                },
                createNonceStr(len) {
                    var e = len ? len : 16;
                    var t =
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
                        a = t.length,
                        n = "";
                    for (i = 0; i < e; i++)
                        n += t.charAt(Math.floor(Math.random() * a));
                    return n;
                },
                // PDF修改名称
                funcBt() {
                    if (this.addedPreviewFile.length) {
                        this.isShow = false;
                        this.show = true;
                        // $(".curtain").css("display", "block");
                    } else {
                        mui.toast("请先上传图片", {
                            duration: "long",
                            type: "div",
                        });
                        this.read = 0;
                    }
                },
                // 确定发送邮箱
                continueBtn() {
                    if (!this.name) {
                        mui.toast("文件名不能为空", {
                            duration: "long",
                            type: "div",
                        });
                    }
                    if (this.name) {
                        var reg = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;
                        if (reg.test(this.name)) {
                            this.Derive();
                        } else {
                            mui.toast("只能输入中英文、数字、下划线！", {
                                duration: "long",
                                type: "div",
                            });
                        }
                    }
                },
                sendEmail() {
                    toMail = sessionStorage.getItem("toMail")
                    // 发送邮箱前判断是否注册过
                    if (!toMail) {
                        $(".curtain").css("display", "none")
                        mui.toast('请前往“我的”页面设置内网邮箱！', {
                            duration: 'long',
                            type: 'div'
                        })
                        return
                    }
                    var btnArray = ["取消", "确定"];
                    var i = 0
                    mui.confirm(
                        "是否发送邮箱？",
                        "消息提醒",
                        btnArray,
                        (e) => {
                            if (i > 0) return
                            i++
                            if (e.index == 1) {
                                this.Derive()
                            } 
                        }
                    );
                },
                // 导出文件
                Derive() {
                    if (this.addedPreviewFile.length) {
                        $(".curtain").css("display", "block");
                        const userId = sessionStorage.getItem("userId");
                        const orgId = sessionStorage.getItem("unitId");
                        if (sessionStorage.getItem("iscp_port")) {
                            iscp_port = sessionStorage.getItem("iscp_port");
                        } else {
                            iscp_port = "";
                        }
                        var timestamp = new Date().getTime() + ""
                        let data = {
                            id: this.batchId,
                            fileName: this.name, //文本名称
                            orgId: orgId, //单位id
                            userId: userId, //用户id
                            timestamp: timestamp,
                        };
                        let AuthenticationSession =
                            sessionStorage.getItem("Authentication");
                        data = JSON.stringify(data);
                        let sign = sm3(data);
                        $.ajax({
                            url: localUrlLink + iscp_port + "/photoTransfer/IdentificationFile/updatePdfName",
                            type: "post",
                            async: false, //是否同步，false表示同步请求
                            dataType: "json",
                            data: data,
                            headers: {
                                "Content-Type": "application/json;charset=UTF-8",
                                Authentication: AuthenticationSession,
                                sign: sign,
                                userId: userId,
                                timestamp: timestamp
                            },
                            success: (res, txt, xhr) => {
                                $(".curtain").css("display", "none");
                                if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                                    let Authentication = xhr.getResponseHeader("Authentication")
                                    if (res.code == 200) {
                                        if (Authentication) {
                                            sessionStorage.setItem("Authentication", Authentication);
                                        }
                                         // 清空
                                        this.addedPreview = []
                                        this.addedPreviewFile = []
                                        this.addedPreviewFileIds = []
                                        mui.toast("发送成功，请在内网邮箱中查收", {
                                                duration: 'long',
                                                type: 'div'
                                            })
                                        this.compatibleInput();
                                        addOperator(6, 5, "图片转PDF", 1, 1, "成功！", "", "picture");
                                    } else {
                                        mui.toast(res.resultValue, {
                                            duration: 'long',
                                            type: 'div'
                                        })
                                    }
                                } else {
                                    mui.toast("完整性校验失败！", {
                                        duration: 1300,
                                        type: 'div'
                                    })
                                }
                            },
                            error: (e) => {
                                $(".curtain").css("display", "none");
                                mui.toast("邮箱发送失败！", {
                                    duration: "long",
                                    type: "div",
                                });
                                addOperator(6, 5, "图片转PDF", 1, 0, "失败！", "", "picture");
                            },
                        });
                    } else {
                        mui.toast("请上传图片", {
                            duration: 1000,
                            type: "div",
                        });
                    }
                },
                cleanImg() {
                    this.addedPreviewFile = [];
                    if (this.addedPreviewFile.length < 3) {
                        this.showUpload = false;
                    }
                },
                createSgin(data) {
                    let hashData = sm3(data);
                    let hashData_last = sm3(hashData);
                    hashData_last = hashData_last.substr(0, 5);
                    hashData += hashData_last;
                    let sign = hashData;
                    return sign;
                },
                quxiao() {
                    this.isShow = true;
                    this.show = false;
                    $(".curtain").css("display", "none");
                },
                showSize(base64url) {
                    //把头部去掉
                    var str = base64url.replace("data:image/png;base64,", "");
                    // 找到等号，把等号也去掉
                    var equalIndex = str.indexOf("=");
                    if (str.indexOf("=") > 0) {
                        str = str.substring(0, equalIndex);
                    }
                    // 原来的字符流大小，单位为字节
                    var strLength = str.length;
                    // 计算后得到的文件流大小，单位为字节
                    var fileLength = parseInt(strLength - (strLength / 8) * 2);
                    // 由字节转换为kb
                    var size = "";
                    size = (fileLength / 1024).toFixed(2);
                    var sizeStr = size + ""; //转成字符串
                    var index = sizeStr.indexOf("."); //获取小数点处的索引
                    var dou = sizeStr.substr(index + 1, 2); //获取小数点后两位的值
                    if (dou == "00") {
                        //判断后两位是否为00，如果是则删除00
                        return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
                    }
                    return size;
                },
                funcBtn() {
                    let inputDOM = this.$refs.inputer;
                    let file = inputDOM.files[0];
                    let re = new FileReader();
                    re.readAsDataURL(file);
                    let that = this;
                    re.onload = (re) => {
                        that.addedPreviewFile = re.target.result;
                        var size = this.showSize(that.addedPreviewFile);
                        if (size > 10000) {
                            mui.toast("图片大小不能超过10M", {
                                duration: "long",
                                type: "div",
                            });
                            that.addedPreviewFile = "";
                        } else { }
                    };
                },
                // 安卓计算图片大小
                imageSize(base64Str) {
                    const indexBase64 = base64Str.indexOf("base64,");
                    if (indexBase64 < 0) return -1;
                    const str = base64Str.substr(indexBase64 + 6);
                    return (str.length * 0.75).toFixed(2);
                },
            },
        });
    </script>
</body>

</html>